package echat.future.cn.echat.video;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.dingmouren.layoutmanagergroup.viewpager.OnViewPagerListener;
import com.dingmouren.layoutmanagergroup.viewpager.ViewPagerLayoutManager;
import com.netease.nim.avchatkit.AVChatKit;
import com.netease.nim.avchatkit.AVChatUserData;
import com.netease.nim.avchatkit.activity.AVChatActivity;
import com.netease.nimlib.sdk.avchat.constant.AVChatType;
import com.xiao.nicevideoplayer.NiceVideoPlayer;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.dialog.YuyueDialog;
import echat.future.cn.echat.dialog.YuyueTipDialog;
import echat.future.cn.echat.home.AnchorHomeActivity;
import echat.future.cn.echat.home.DearRankingActivity;
import echat.future.cn.echat.my.utils.ImageLoadUtils;
import echat.future.cn.echat.my.utils.UserHelper;
import echat.future.cn.echat.my.view.RechargeActivity;
import echat.future.cn.echat.video.domain.GiftData;
import echat.future.cn.echat.video.domain.VideoData;
import echat.future.cn.echat.video.utils.VideoController;
import lumingweihua.future.cn.baselibgxh.base.BaseFragment;
import lumingweihua.future.cn.baselibgxh.base.GiftFragment;
import lumingweihua.future.cn.baselibgxh.base.MyApplication;
import lumingweihua.future.cn.baselibgxh.dialog.ChoiseType;
import lumingweihua.future.cn.baselibgxh.dialog.YesOrNoDialog;
import lumingweihua.future.cn.baselibgxh.dialog.YesOrNoDialogEntity;
import lumingweihua.future.cn.baselibgxh.network.AbstractRequest;
import lumingweihua.future.cn.baselibgxh.network.JsonElementRequest;
import lumingweihua.future.cn.baselibgxh.network.PureListRequest;
import lumingweihua.future.cn.baselibgxh.network.ReqTag;
import lumingweihua.future.cn.baselibgxh.network.entity.DefaultMamahaoServerError;
import lumingweihua.future.cn.baselibgxh.network.entity.MamaHaoServerError;
import lumingweihua.future.cn.baselibgxh.utils.CommonUtils;
import lumingweihua.future.cn.baselibgxh.utils.ImageUtils;
import lumingweihua.future.cn.baselibgxh.utils.SharedPreference;

/**
 * Created by Administrator on 2018/8/9.
 */

public class VideoFragment  extends BaseFragment {
    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_video, container, false);
    }

    private RecyclerView mRecyclerView;
    private ViewPagerLayoutManager mLayoutManager;
    private List<VideoData> videoDatas;
    private View rl_gift;
    private View rl_pay;
    private View view_mask;
    public boolean isCity;
    public String member_id;
    public String vid;

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    private ChoiseType choiseType;
    private List<GiftData> giftDatas;
    private MyAdapter adapter;
    private int currentPos;
    @Override
    protected void onFirstUserVisible() {
        super.onFirstUserVisible();
        mRecyclerView = (RecyclerView) findView(R.id.recycler);
        rl_gift = findView(R.id.rl_gift);
        rl_pay = findView(R.id.rl_pay);
        view_mask = findView(R.id.view_mask);
        view_mask.setOnClickListener(this);
//        findView(R.id.tv_cancel).setOnClickListener(this);
        findView(R.id.iv_close).setOnClickListener(this);
        findView(R.id.bt_pay).setOnClickListener(this);

        mLayoutManager = new ViewPagerLayoutManager(baseActivity, OrientationHelper.VERTICAL);

        videosMap = new HashMap<>();
//        controller.setTitle(courseDetailData.getName());
        choiseType = new ChoiseType(context,R.style.dialog_sex);
        choiseType.setOnForResultCallBack(new ChoiseType.OnForResultCallBack() {
            @Override
            public void onCallBack(String reason) {
                requestReport(reason);
            }
        });

        videoDatas = new ArrayList<>();

        mRecyclerView.setLayoutManager(mLayoutManager);
        adapter = new MyAdapter();
        mRecyclerView.setAdapter(adapter);
        initListener();
        requestGoodsDatas();
    }

    public class MyAdapter extends RecyclerView.Adapter{
        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_play_video,parent,false);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            VideoData videoData = videoDatas.get(position);
            videosMap.put(videoData.getId(),((ViewHolder)holder).nice_video_player);
            //信息设置
            baseActivity.showImage(videoData.getAvatar(),((ViewHolder)holder).iv_head,ImageUtils.imgOptionsHead);
            if(videoData.getIs_focus())
                ((ViewHolder)holder).iv_add_focus.setVisibility(View.GONE);
            else
                ((ViewHolder)holder).iv_add_focus.setVisibility(View.VISIBLE);

            if(MyApplication.getInstance().isZhubo){
                ((ViewHolder)holder).tv_gift.setVisibility(View.GONE);
                ((ViewHolder)holder).ll_video.setVisibility(View.GONE);
            }

            ((ViewHolder)holder).tv_tag.setText(videoData.getUsername());
            ((ViewHolder)holder).tv_job.setText(videoData.getSign());
            if("1".equals(videoData.getAnchor_status()))
                ((ViewHolder)holder).iv_state.setImageResource(R.drawable.btn_zaixian);
            else if("2".equals(videoData.getAnchor_status()))
                ((ViewHolder)holder).iv_state.setImageResource(R.drawable.btn_zailiao);
            else
                ((ViewHolder)holder).iv_state.setImageResource(R.drawable.btn_lixian);


//            ((ViewHolder)holder).tv_state.setBackgroundResource("1".equals(videoData.getAnchor_status())?R.drawable.dot_green:R.drawable.dot_lixian);
            //举报
            ((ViewHolder)holder).tv_more.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ((ViewHolder)holder).tv_report.setVisibility(((ViewHolder)holder).tv_report.getVisibility()==View.VISIBLE?View.GONE:View.VISIBLE);
                }
            });
            ((ViewHolder)holder).tv_report.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ((ViewHolder)holder).tv_report.setVisibility(View.GONE);
                    choiseType.show();
                }
            });
            //收藏和热度
            ((ViewHolder)holder).tv_collection.setText(videoData.getColletion_num()+"");
            ((ViewHolder)holder).tv_hot.setText(videoData.getView_num()+"");
            ((ViewHolder)holder).tv_collection.setCompoundDrawables(
                    null, CommonUtils.GetDrawable(context, videoData.getIs_collection()?R.drawable.shiping_shoucang_xuanqu:R.drawable.shiping_shoucang_mr),
                    null, null);

            ((ViewHolder)holder).tv_gift.setOnClickListener(VideoFragment.this);
            ((ViewHolder)holder).tv_collection.setOnClickListener(VideoFragment.this);
            ((ViewHolder)holder).iv_add_focus.setOnClickListener(VideoFragment.this);
            ((ViewHolder)holder).iv_head.setOnClickListener(VideoFragment.this);
//            ((ViewHolder)holder).tv_hot.setOnClickListener(VideoFragment.this);
            ((ViewHolder)holder).ll_ranks.setOnClickListener(VideoFragment.this);
            ((ViewHolder)holder).ll_video.setOnClickListener(VideoFragment.this);
            if(videoData.getClose_list()!=null && videoData.getClose_list().size()>0){
                //亲密帮
                ((ViewHolder)holder).ll_ranks.setVisibility(View.VISIBLE);

                baseActivity.showImage(videoData.getClose_list().get(0).getUser_avatar(),((ViewHolder)holder).iv_rank_01,ImageUtils.imgOptionsHead);
                if(videoData.getClose_list().size()==2){
                    ((ViewHolder)holder).rl_rank03.setVisibility(View.GONE);
                    ((ViewHolder)holder).rl_rank02.setVisibility(View.VISIBLE);
                    baseActivity.showImage(videoData.getClose_list().get(1).getUser_avatar(),((ViewHolder)holder).iv_rank_01,ImageUtils.imgOptionsHead);
                }else if(videoData.getClose_list().size()==3){
                    ((ViewHolder)holder).rl_rank03.setVisibility(View.VISIBLE);
                    ((ViewHolder)holder).rl_rank02.setVisibility(View.VISIBLE);
                    baseActivity.showImage(videoData.getClose_list().get(2).getUser_avatar(),((ViewHolder)holder).iv_rank_01,ImageUtils.imgOptionsHead);
                }else{
                    ((ViewHolder)holder).rl_rank03.setVisibility(View.GONE);
                    ((ViewHolder)holder).rl_rank02.setVisibility(View.GONE);
                }
            }else{
                ((ViewHolder)holder).ll_ranks.setVisibility(View.GONE);
            }
        }

        @Override
        public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
            super.onViewRecycled(holder);

        }

        @Override
        public int getItemCount() {
            return videoDatas.size();
        }

    }

    private final int REQUEST_REPORT = 1;
    private final int REQUEST_HOT = 3;
    private final int REQUEST_COLLECT = 2;
    private final int REQUEST_CANCEL_COLLECT = 4;
    private final int REQUEST_FOLLOW = 5;
    private final int REQUEST_DATAS = 6;
    private final int REQUEST_PAY = 9;

    public void requestGoodsDatas() {
        // TODO Auto-generated method stub
        baseActivity.showProgressBar(this);
        PureListRequest<VideoData, MamaHaoServerError> req = new PureListRequest<>(
                context,
                "/api/tab_video",
                this,
                VideoData.class);

        req.setParam("token", UserHelper.getToken());
        if(!TextUtils.isEmpty(member_id))
            req.setParam("member_id", member_id);
        if(isCity){
            req.setParam("type", "city");
            if(!TextUtils.isEmpty(MyApplication.getInstance().getCity()) && MyApplication.getInstance().getCity().endsWith("市"))
                req.setParam("city", MyApplication.getInstance().getCity().substring(0,MyApplication.getInstance().getCity().length()-1));
            else
                req.setParam("city", MyApplication.getInstance().getCity());

        }

        baseActivity.addRequestQueue(req, REQUEST_DATAS, new ReqTag.Builder().handleSimpleRes(true));

    }

    /**
     * 举报
     */
    private void requestReport(String content) {

        JsonElementRequest<DefaultMamahaoServerError> req = new JsonElementRequest<DefaultMamahaoServerError>(
                context, "/home/addReport", this);

        req.setParam("uid", UserHelper.getUserId());
        req.setParam("anchor_id", videoDatas.get(currentPos).getMember_id());
        req.setParam("voide_id", videoDatas.get(currentPos).getId());
        req.setParam("reason", content);

        baseActivity.addRequestQueue(req, REQUEST_REPORT, new ReqTag.Builder().handleSimpleRes(true));
    }

    /**
     * 收藏
     */
    private void requestCollect(boolean isCollect) {
        baseActivity.showProgressBar(this);
//        JsonElementRequest<DefaultMamahaoServerError> req = new JsonElementRequest<DefaultMamahaoServerError>(
//                context, "/api/send_anchor_status", this);
        JsonElementRequest<DefaultMamahaoServerError> req = new JsonElementRequest<DefaultMamahaoServerError>(
                context, "/api/user/ope_video", this);

        req.setParam("video_id", videoDatas.get(currentPos).getId());
        req.setParam("token", UserHelper.getToken());
        req.setParam("type", isCollect?"1":"2");
//        req.setParam("member_id", videoDatas.get(currentPos).getMember_id());
//        req.setParam("status", isCollect?"1":"0");

        baseActivity.addRequestQueue(req, isCollect?REQUEST_COLLECT:REQUEST_CANCEL_COLLECT, new ReqTag.Builder().handleSimpleRes(true));
    }
    /**
     * 热
     */
    private void requestHot() {

        JsonElementRequest<DefaultMamahaoServerError> req = new JsonElementRequest<DefaultMamahaoServerError>(
                context, "/api/add_video_view_num", this);

        req.setParam("video_id", videoDatas.get(currentPos).getId());
        req.setParam("token", UserHelper.getToken());

        baseActivity.addRequestQueue(req, REQUEST_HOT, new ReqTag.Builder().handleSimpleRes(true));
    }
    /**
     * 关注
     */
    private void requestFollow() {
        baseActivity.showProgressBar(this);
//        JsonElementRequest<DefaultMamahaoServerError> req = new JsonElementRequest<DefaultMamahaoServerError>(
//                context, "/api/user/get_one_anchor", this);
        JsonElementRequest<DefaultMamahaoServerError> req = new JsonElementRequest<DefaultMamahaoServerError>(
                context, "/api/user/ope_fans", this);

        req.setParam("type", "1");
        req.setParam("token", UserHelper.getToken());
        req.setParam("member_id", videoDatas.get(currentPos).getMember_id());

        baseActivity.addRequestQueue(req, REQUEST_FOLLOW, new ReqTag.Builder().handleSimpleRes(true));
    }
    /**
     * 支付
     */
    private void requestPay() {
        baseActivity.showProgressBar(this);
        JsonElementRequest<DefaultMamahaoServerError> req = new JsonElementRequest<DefaultMamahaoServerError>(
                context, "/api/user/pay_video"+"?token="+UserHelper.getToken()
                +"&video_id="+videoDatas.get(currentPos).getId()
                +"&anchor_id="+videoDatas.get(currentPos).getMember_id(), this);

        req.setParam("video_id", videoDatas.get(currentPos).getId());
        req.setParam("token", UserHelper.getToken());
        req.setParam("anchor_id", videoDatas.get(currentPos).getMember_id());

        baseActivity.addRequestQueue(req, REQUEST_PAY, new ReqTag.Builder().handleSimpleRes(true));
    }

    private int videoIndex=0;
    @Override
    protected void onResponseSuccess(ReqTag tag, Object data) {
        super.onResponseSuccess(tag, data);
        switch (tag.getReqId()) {
            case REQUEST_DATAS:

                if((List<VideoData>)data!=null){
                    videoDatas.addAll((List<VideoData>)data);
                    if(!TextUtils.isEmpty(vid)){
                        //主播的小视频
                        for(int i=0;i<videoDatas.size();i++){
                            if(videoDatas.get(i).getId().equals(vid)){
                                videoIndex = i;
                                break;
                            }
                        }
                    }
                }
                adapter.notifyDataSetChanged();

                if(videoIndex>0){
                    mLayoutManager.scrollToPosition(videoIndex);
//                changePlayVideo(2);
                }
                break;
            case REQUEST_REPORT:
                //举报
                baseActivity.showToast("举报成功");
                break;
            case REQUEST_COLLECT:
                tv_collection.setText(videoDatas.get(currentPos).getColletion_num()+1+"");
                tv_collection.setCompoundDrawables(
                        null, CommonUtils.GetDrawable(context, R.drawable.shiping_shoucang_xuanqu),
                        null, null);
                break;
            case REQUEST_CANCEL_COLLECT:
                int c = videoDatas.get(currentPos).getColletion_num();
                if(c>0)
                    tv_collection.setText(c-1+"");

                tv_collection.setCompoundDrawables(
                        null, CommonUtils.GetDrawable(context, R.drawable.shiping_shoucang_mr),
                        null, null);
                break;
            case REQUEST_FOLLOW:
                iv_add_focus.setVisibility(View.GONE);
                break;
            case REQUEST_PAY:
                videoDatas.get(currentPos).setCan_see("1");
                mNiceVideoPlayer.start();
                requestHot();
                view_mask.setVisibility(View.GONE);
                rl_pay.setVisibility(View.GONE);
                break;

            default:
                break;
        }
    }

    @Override
    protected void onResponseFailure(ReqTag tag, MamaHaoServerError error, AbstractRequest.MamaHaoError clientError) {
        super.onResponseFailure(tag, error, clientError);
        switch (tag.getReqId()) {
            case REQUEST_PAY:
                baseActivity.showToast("支付失败");
                break;

            default:
                break;
        }
    }

    private void initListener(){
        mLayoutManager.setOnViewPagerListener(new OnViewPagerListener() {
            @Override
            public void onInitComplete() {
                changePlayVideo(videoIndex);
            }

            @Override
            public void onPageRelease(boolean isNext,int position) {
            }
            @Override
            public void onPageSelected(int position,boolean isBottom) {
//                Log.e(TAG,"选中位置:"+position+"  是否是滑动到底部:"+isBottom);
                currentPos = position;
                changePlayVideo(position);
            }

        });
    }

    private HashMap<String,NiceVideoPlayer> videosMap;

    public class ViewHolder extends RecyclerView.ViewHolder{

        NiceVideoPlayer nice_video_player;
        ImageView tv_more;
        ImageView tv_report;
        ImageView iv_state;
        TextView tv_tag;
//        View tv_state;
//        TextView tv_state_name;
        TextView tv_job;
        TextView tv_gift;
        ImageView iv_head;
        ImageView iv_add_focus;
        TextView tv_collection;
        TextView tv_hot;
        RelativeLayout rl_rank01;
        ImageView iv_rank_01;
        RelativeLayout rl_rank02;
        ImageView iv_rank_02;
        RelativeLayout rl_rank03;
        ImageView iv_rank_03;
        LinearLayout ll_ranks;
        LinearLayout ll_video;

        public ViewHolder(View itemView) {
            super(itemView);
            nice_video_player = itemView.findViewById(R.id.nice_video_player);
            tv_more = itemView.findViewById(R.id.tv_more);
            tv_report = itemView.findViewById(R.id.tv_report);
            tv_tag = itemView.findViewById(R.id.tv_tag);
            iv_state = itemView.findViewById(R.id.iv_state);
//            tv_state_name = itemView.findViewById(R.id.tv_state_name);
            tv_job = itemView.findViewById(R.id.tv_job);
            tv_gift = itemView.findViewById(R.id.tv_gift);
            iv_head = itemView.findViewById(R.id.iv_head);
            iv_add_focus = itemView.findViewById(R.id.iv_add_focus);
            tv_collection = itemView.findViewById(R.id.tv_collection);
            tv_hot = itemView.findViewById(R.id.tv_hot);
            rl_rank01 = itemView.findViewById(R.id.rl_rank01);
            iv_rank_01 = itemView.findViewById(R.id.iv_rank_01);
            rl_rank02 = itemView.findViewById(R.id.rl_rank02);
            iv_rank_02 = itemView.findViewById(R.id.iv_rank_02);
            rl_rank03 = itemView.findViewById(R.id.rl_rank03);
            iv_rank_03 = itemView.findViewById(R.id.iv_rank_03);
            ll_ranks = itemView.findViewById(R.id.ll_ranks);
            ll_video = itemView.findViewById(R.id.ll_video);
        }
    }

    private int lastChangePos = -1;
    private NiceVideoPlayer mNiceVideoPlayer;
    /**
     * 修改播放视频源
     * @param position
     */
    private void changePlayVideo(int position){
        if(lastChangePos == position)
            return;

        VideoData vd = videoDatas.get(position);

        mNiceVideoPlayer = videosMap.get(vd.getId());

        if(mNiceVideoPlayer!=null){
//            try {
            if(lastChangePos>0)
                videosMap.get(videoDatas.get(lastChangePos).getId()).release();
//            } catch (Exception e) {
//                // TODO: handle exception
//            }

            VideoController controller=new VideoController(context, new VideoController.PlayChangeListener() {
                @Override
                public void playChange() {
                    if(vd.getCan_see()){
                        //免费
                        if(mNiceVideoPlayer.isPlaying()){
                            mNiceVideoPlayer.pause();
                        }else{
                            mNiceVideoPlayer.restart();
                        }
                    }else{
                        //付费
                        payVideo();
                    }
                }
            });
//            controller.setTitle("");
            if(vd.getCan_see())
                baseActivity.showImage(vd.getImg(),
                        controller.imageView(),ImageUtils.imgOptionsSmall);
            else
                ImageLoadUtils.loadBlurImage(baseActivity,vd.getImg(),controller.imageView());


            mNiceVideoPlayer.setPlayerType(NiceVideoPlayer.TYPE_IJK); // or NiceVideoPlayer.TYPE_NATIVE
            mNiceVideoPlayer.setUp(vd.getVideo(),null);
            mNiceVideoPlayer.setController(controller);
            mNiceVideoPlayer.seekTo(0);
//            mNiceVideoPlayer.enterFullScreen();
            if(vd.getCan_see()){
                requestHot();
                mNiceVideoPlayer.start();
            }
            else
                payVideo();

//            mNiceVideoPlayer.setpla
        }

        lastChangePos = position;
//        mNiceVideoPlayer.releasePlayer();
    }

    public void pause(){
        if(mNiceVideoPlayer != null)
            mNiceVideoPlayer.pause();
    }

    public void resume(){
        if(mNiceVideoPlayer != null && lastChangePos>=0){
            VideoData vd = videoDatas.get(lastChangePos);
            VideoController controller=new VideoController(context, new VideoController.PlayChangeListener() {
                @Override
                public void playChange() {
                    if(vd.getCan_see()){
                        //免费
                        if(mNiceVideoPlayer.isPlaying()){
                            mNiceVideoPlayer.pause();
//                    iv_play.setVisibility(View.VISIBLE);
                        }else{
                            mNiceVideoPlayer.restart();
//                    iv_play.setVisibility(View.GONE);
                        }
                    }else{
                        //付费
                        payVideo();
                    }
                }
            });
//            controller.setTitle("");

            baseActivity.showImage(vd.getImg(),
                    controller.imageView(),ImageUtils.imgOptionsSmall);
            mNiceVideoPlayer.setPlayerType(NiceVideoPlayer.TYPE_IJK); // or NiceVideoPlayer.TYPE_NATIVE
            mNiceVideoPlayer.setUp(vd.getVideo(),null);
            mNiceVideoPlayer.setController(controller);
            mNiceVideoPlayer.start();
        }
    }

    private void payVideo(){

        new YesOrNoDialog(context, new YesOrNoDialogEntity("该视频需付费观看\n您确认付费麽?", "取消", "立即付费"), new YesOrNoDialog.OnYesOrNoDialogClickListener() {
            @Override
            public void onYesOrNoDialogClick(YesOrNoDialog.YesOrNoType yesOrNoType) {
                switch (yesOrNoType) {
                    case BtnOk:
                        view_mask.setVisibility(View.VISIBLE);
                        rl_pay.setVisibility(View.VISIBLE);
                        setText(R.id.tv_coin,"E币："+videoDatas.get(currentPos).getVideo_price());
                        break;

                    default:
                        break;
                }
            }
        }).show();
    }

    public void restart(){
        if(mNiceVideoPlayer != null)
            mNiceVideoPlayer.restart();
    }

    private TextView tv_collection;
    private TextView tv_hot;
    private ImageView iv_add_focus;
    private GiftFragment giftFragment;
    @Override
    protected void processClick(View v) {
        switch (v.getId()) {
            case R.id.tv_gift:
                if(giftFragment==null){
                    giftFragment = new GiftFragment();
                    giftFragment.setListener(videoDatas.get(currentPos).getMember_id(), new GiftFragment.GiftChangeListener() {
                        @Override
                        public void onSendGift(String id) {

                        }

                        @Override
                        public void onDissmiss() {
                            rl_gift.setVisibility(View.GONE);
                        }
                    });
                    getChildFragmentManager().beginTransaction()
                            .add(R.id.rl_gift, giftFragment).commit();
                }
                rl_gift.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_collection:
                tv_collection = (TextView)v;
                requestCollect(!videoDatas.get(currentPos).getIs_collection());
                break;
//            case R.id.tv_hot:
//                tv_hot = (TextView)v;
//                requestHot();
//                break;
            case R.id.iv_add_focus:
                iv_add_focus = (ImageView) v;
                requestFollow();
                break;
            case R.id.iv_head:
                startActivity(new Intent(context, AnchorHomeActivity.class).putExtra("extra_str_id", videoDatas.get(currentPos).getMember_id()));
                break;
            case R.id.ll_ranks:
                startActivity(new Intent(context, DearRankingActivity.class)
                        .putExtra("extra_str_id",videoDatas.get(currentPos).getId()));
                break;
            case R.id.ll_video:
                //
                if(!"1".equals(videoDatas.get(currentPos).getAnchor_status())){
                    new YesOrNoDialog(context, new YesOrNoDialogEntity("当前主播不在线，请稍后再试", null, "我知道了"), new YesOrNoDialog.OnYesOrNoDialogClickListener() {
                                @Override
                                public void onYesOrNoDialogClick(YesOrNoDialog.YesOrNoType yesOrNoType) {
                                    switch (yesOrNoType) {
                                        case BtnOk:

                                            break;

                                        default:
                                            break;
                                    }
                                }
                            }).show();
                }else{
                    String date = SharedPreference.getString(context,"freedate");
                    String dateNowStr = new SimpleDateFormat("yyyy-MM-dd").format(new Date());

                    if(videoDatas.get(currentPos).getFirst_free() && !date.contains(dateNowStr)){
                        //限免
//                        SharedPreference.saveToSP(context,"freedate",date+","+dateNowStr);
                        VideoData videoData = videoDatas.get(currentPos);
                        AVChatUserData avChatUserData = new AVChatUserData(
                                UserHelper.getUserId()
                                ,videoData.getMember_id()
                                , videoData.getAvatar()
                                , videoData.getUsername()
                                , "1"
                                , true
                                , videoData.getPrice()
                                ,60);
                        AVChatKit.outgoingCall(baseActivity,
                                videoData.getMobile(),
                                videoData.getUsername(),
                                AVChatType.VIDEO.getValue(),
                                AVChatActivity.FROM_INTERNAL,avChatUserData);
                    }else if(MyApplication.getInstance().e_money<videoDatas.get(currentPos).getPrice()){
                        new YesOrNoDialog(context, new YesOrNoDialogEntity("您的E币余额不够，不能与主播视频\n请及时充值", "我知道了", "立即充值"), new YesOrNoDialog.OnYesOrNoDialogClickListener() {
                            @Override
                            public void onYesOrNoDialogClick(YesOrNoDialog.YesOrNoType yesOrNoType) {
                                switch (yesOrNoType) {
                                    case BtnOk:
                                        RechargeActivity.openActivity(context,RechargeActivity.class);
                                        break;

                                    default:
                                        break;
                                }
                            }
                        }).show();

                    }else{
                        VideoData videoData = videoDatas.get(currentPos);
                        AVChatUserData avChatUserData = new AVChatUserData(
                                UserHelper.getUserId()
                                ,videoData.getMember_id()
                                , videoData.getAvatar()
                                , videoData.getUsername()
                                , "1"
                                , true
                                , videoData.getPrice()
                                ,0);
                        AVChatKit.outgoingCall(baseActivity,
                                videoData.getMobile(),
                                videoData.getUsername(),
                                AVChatType.VIDEO.getValue(),
                                AVChatActivity.FROM_INTERNAL,avChatUserData);
                    }
                }

                break;
            case R.id.bt_pay:
                requestPay();
                break;
            case R.id.iv_close:
            case R.id.view_mask:
            case R.id.tv_cancel:
                view_mask.setVisibility(View.GONE);
                rl_gift.setVisibility(View.GONE);
                rl_pay.setVisibility(View.GONE);
                break;

            default:
                break;
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if(mNiceVideoPlayer != null){
            mNiceVideoPlayer.pause();
        }
    }

}
